package com.example.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.po.Checkapply;
import com.example.service.CheckapplyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/checkapply")
public class CheckapplyController {
    @Autowired
    private CheckapplyService checkapplyService;

    @RequestMapping("/getbyregistid")
    public List<Checkapply> getbyregistid(Integer registid) {
        System.out.println("registid:"+registid);
        QueryWrapper<Checkapply> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("RegistID",registid);
        return checkapplyService.list(queryWrapper);
    }

    @RequestMapping("/batchInsert")
    public Boolean addlist(@RequestBody List<Checkapply> list) {
        list.forEach(item->{
            item.setCreationtime(new Date());
        });
        return checkapplyService.saveOrUpdateBatch(list);
    }

    @RequestMapping("/getbymid")
    public Map<String, Object> getbymid(@RequestParam Integer mid) {
        return checkapplyService.getinfoByMedicalID(mid);
    }

    @RequestMapping("/changebyregistid")
    public Boolean changebyregistid(@RequestParam String registid) {
        QueryWrapper<Checkapply> queryWrapper = new QueryWrapper<>();
        Integer id = Integer.parseInt(registid);
        queryWrapper.eq("RegistID",id);
        Checkapply checkapply = new Checkapply();
        checkapply.setState(2);
        return checkapplyService.update(checkapply,queryWrapper);
    }

    @RequestMapping("getbydeptname")
    public Map<String, Object> getbydeptname(@RequestParam String deptname,
                                             @RequestParam Integer state,
                                             @RequestParam String realname) {
        return checkapplyService.getbydeptname(deptname,state,realname);
    }

    @RequestMapping("changes")
    public Boolean changes(@RequestParam Integer id,@RequestParam String result,@RequestParam Integer operid) {
        Checkapply checkapply = new Checkapply();
        checkapply.setId(id);
        checkapply.setState(4);
        checkapply.setResult(result);
        checkapply.setCheckoperid(operid);
        checkapply.setResultoperid(operid);
        checkapply.setChecktime(new Date());
        checkapply.setResulttime(new Date());
        return checkapplyService.updateById(checkapply);
    }
}
